#!/usr/bin/env python3
# coding:utf-8
class Node:
    def __init__(self,value):
        self.data = value
        self.next = None

class list_stack:
    def __init__(self):
        self.top = None
    
    def empty(self):
        return self.top == None

    def push(self,value):
        if self.top == None:
            self.top = Node(value)
        else:
            new_node = Node(value)
            new_node.next = self.top
            self.top = new_node
    
    def pop(self):
        if self.empty():
            raise Exception("stack is empty")
        cur = self.top
        self.top = self.top.next
        del cur

    def peek(self):
        if self.empty():
            raise Exception("stack is empty")
        return self.top.data
    
    def show(self):
        if self.empty():
            raise Exception("stack is empty")
        cur = self.top
        while cur != None:
            print(cur.data,end=" ")
            cur = cur.next
        print()

if __name__ == '__main__':
    s = list_stack()
    s.push(1)
    s.push(2)
    s.push(3)
    s.push(4)
    s.push(5)
    s.show()
    print("peek:",s.peek())
    
    s.pop()
    s.show()
    print("peek:",s.peek())